using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace QiHe.ReliableData
{
    public class ValueSetConverter : StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            //true means show a combobox
            return true;
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            //true will limit to list. false will show the list, 
            //but allow free-form entry
            string dataTypeName = context.Instance.GetType().Name;
            string propertyName = context.PropertyDescriptor.Name;
            return Program.MainForm.IsFixedValueSet(dataTypeName, propertyName);
        }

        public override System.ComponentModel.TypeConverter.StandardValuesCollection
               GetStandardValues(ITypeDescriptorContext context)
        {
            string dataTypeName = context.Instance.GetType().Name;
            string propertyName = context.PropertyDescriptor.Name;
            return new StandardValuesCollection(Program.MainForm.GetValueSet(dataTypeName, propertyName));
        }
    }
}
